//
//  HJSellOderDetailController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/30.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJSellOderDetailController.h"
#import "HJInputViewController.h" // 录入单号
#import "HJOrderDetailModel.h"
#import "HJLogisticsViewController.h"

@interface HJSellOderDetailController ()
@property (weak, nonatomic) IBOutlet UIImageView *sellImage;
@property (weak, nonatomic) IBOutlet UILabel *shipTitle;
@property (weak, nonatomic) IBOutlet UILabel *shipMoney;
@property (weak, nonatomic) IBOutlet UILabel *statues;
@property (weak, nonatomic) IBOutlet UILabel *goodsNoAndTime;

@property (weak, nonatomic) IBOutlet UILabel *shoeCode;
@property (weak, nonatomic) IBOutlet UILabel *shoeMoney;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *sellTimeSuperH;
@property (weak, nonatomic) IBOutlet UILabel *sellTime;
@property (weak, nonatomic) IBOutlet UILabel *remainTime;

@property (weak, nonatomic) IBOutlet UILabel *careNo;

@property (weak, nonatomic) IBOutlet UILabel *serveMoney;
@property (weak, nonatomic) IBOutlet UILabel *earningsMoney;


@property (weak, nonatomic) IBOutlet UILabel *takeGoods;
@property (weak, nonatomic) IBOutlet UILabel *address;
@property (weak, nonatomic) IBOutlet UILabel *shipStatue;

@property (weak, nonatomic) IBOutlet UITextField *couriernumberTF;
@property (weak, nonatomic) IBOutlet UIView *btmView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btmY;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *logisticsY;
@property (weak, nonatomic) IBOutlet UIButton *logisticsBtn;
@property (weak, nonatomic) IBOutlet UIView *logisticsV;
@property (weak, nonatomic) IBOutlet UILabel *logisticsLabel;
@property (weak, nonatomic) IBOutlet UIImageView *logisticsImage;

@property (weak, nonatomic) IBOutlet UIView *backView;
@property(nonatomic,strong)HJOrderDetailModel * model;
@end

@implementation HJSellOderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.shipStatue.font = HJFontSize(mScreenWidth/414 *14);
    self.couriernumberTF.layer.borderWidth = 0.5;
    self.couriernumberTF.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.btmView.layer.shadowOpacity = 0.2;
    self.btmView.layer.shadowRadius = 3;
    self.btmView.layer.shadowOffset = CGSizeZero;
    self.btmView.layer.shadowColor = [UIColor blackColor].CGColor;
    
    if (mScreenHeight<812.0f) {
        self.btmY.constant = 0.0f;
    }else {
        self.btmY.constant = 34.0f;
    }
    
    self.sellTime.font = HJFontSize(mScreenWidth/414 * 15);
    self.remainTime.font = HJFontSize(mScreenWidth/414 * 15);
    self.logisticsLabel.font = HJFontSize(mScreenWidth/414 * 15);
    self.goodsNoAndTime.font = HJFontSize(mScreenWidth/414 * 13);
    self.takeGoods.font = HJFontSize(mScreenWidth/414 * 15);
    self.address.font = HJFontSize(mScreenWidth/414 * 15);
    
    [self loadWork];
}

-(void)loadWork {
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"sell_id"] = self.sell_id;
    params[@"type"] = @3;
    [TZHttpTool post:OderDetailAPI params:params success:^(NSDictionary *result) {
        self.model = [[HJOrderDetailModel alloc]init];
        self.model = [HJOrderDetailModel mj_objectWithKeyValues:result[@"data"]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.backView removeFromSuperview];
            [self.sellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",self.model.shoes.avatar_base_url,self.model.shoes.avatar_path]]];
            self.shipTitle.text = self.model.shoes.shoes_name;
            self.shipMoney.text = [NSString stringWithFormat:@"￥%@",self.model.shoes.sell_money];
            self.goodsNoAndTime.text = [NSString stringWithFormat:@"%@  %@",self.model.shoes.shoes_article_number,[CommonTools getTimeStrBytimeSt:self.model.shoes.sell_date]];
            self.shoeCode.text = [NSString stringWithFormat:@"%@码",self.model.shoes_size];
            self.shoeMoney.text = [NSString stringWithFormat:@"￥%@",self.model.pay_reality];
            self.sellTime.text =self.model.shoes_date;
            self.remainTime.text = self.model.day;
            self.careNo.text = [NSString stringWithFormat:@"目前有%@人在关注该款产",self.model.collection];
            self.takeGoods.text = [NSString stringWithFormat:@"%@",self.model.addresser];
            self.address.text = [NSString stringWithFormat:@"%@",self.model.addresser_detail];
            self.serveMoney.text = [NSString stringWithFormat:@"￥%@",self.model.cost];
            self.earningsMoney.text = [NSString stringWithFormat:@"￥%@",self.model.income];
            
            
            if ([self.model.express.status isEqualToString:@""]) {
                self.logisticsY.constant = 0.01f;
                self.logisticsLabel.hidden = YES;
                self.logisticsV.hidden = YES;
                self.logisticsBtn.hidden = YES;
                self.logisticsImage.hidden = YES;
            }
            self.logisticsLabel.text = [NSString stringWithFormat:@"%@  %@",self.model.express.time,self.model.express.status];
            
        });
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
}

- (IBAction)saveBtn:(UIButton *)sender {
    if ([CommonTools isEmpty:self.couriernumberTF.text]) {
        [self showErrorHUDWithError:@"内容不能为空!"];
    }else {
        [TZHttpTool post:ExpressaAddAPI params:@{@"sell_id":self.sell_id,@"express":self.couriernumberTF.text} success:^(NSDictionary *result) {
            [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
            [self showSuccessHUDWithStr:@"录入成功"];
        } failure:^(NSString *msg) {
            [self showErrorHUDWithError:msg];
        }];
    }
   
}
- (IBAction)logistics:(UIButton *)sender {
    HJLogisticsViewController * logisticsVC = [[HJLogisticsViewController alloc]init];
    logisticsVC.shoes_name = self.model.shoes.shoes_name;
    logisticsVC.shoes_size = self.model.shoes_size;
    logisticsVC.shoes_money = self.model.shoes.sell_money;
    logisticsVC.shoes_image = [NSString stringWithFormat:@"%@%@",self.model.shoes.avatar_base_url,self.model.shoes.avatar_path];
    logisticsVC.express = self.model.express.express;
    [self.navigationController pushViewController:logisticsVC animated:YES];
}

@end
